package main

import (
	"context"
	"errors"
	"gitee.com/yms-zero/go-library/igin"
	"gitee.com/yms-zero/go-library/ilog"
	zeroConf "github.com/zeromicro/go-zero/core/conf"
	"go-api/app/global"
	"go-api/app/router"
	"go-api/conf"
	"os"
	"os/signal"
)

func main() {
	//读取配置文件
	var c conf.Conf
	zeroConf.MustLoad("config.yaml", &c)

	//日志
	log, err := ilog.NewLog(c.Log)
	if err != nil {
		panic(err)
	}

	//启动http
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	hs := igin.NewHttp(ctx, c.Http, log, igin.DefaultHttpMiddleware)

	G := global.NewGlobal(&c, hs.Log)

	go hs.WithOptions(router.Router(G)).Run()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, os.Interrupt)
	<-quit

	hs.Close(errors.New("quit")).Complete()
}
